function promisify (fn) {
  return async function (args) {
    return new Promise((resolve, reject) => {
      fn({
        ...(args || {}),
        success: (res) => resolve(res),
        fail: (err) => reject(err.errMsg || err)
      })
    })
  }
}

export function toAsync (...names) {
  return (names || [])
    .map((name) => ({
      name,
      member: uni[name]
    }))
    .filter((t) => typeof t.member === 'function')
    .reduce((r, t) => {
      r[t.name] = promisify(uni[t.name])
      return r
    }, {})
}
